package com.fh.generic;
import java.util.*;

/*
练习:
1. 创建3个学生对象
2. 放入到HashSet中学生对象，使用.
3. 放入到HashMap中，要求Key 是 String name, Value就是学生对象
4.使用两种方式遍历
 */
public class GenericExercise01 {
    public static void main(String[] args) {
        Set<Student> students1 = new HashSet<>();
        students1.add(new Student("小明"));
        students1.add(new Student("小华"));
        students1.add(new Student("小刚"));
        Iterator<Student> iterator = students1.iterator();
        while (iterator.hasNext()) {
            Student information = iterator.next();
            System.out.println(information.getName());
        }
        System.out.println("========================");
        for (Student student : students1) {
            System.out.println(student.getName());
        }
        Map<String, Student> Hm = new HashMap<>();
        Hm.put("jack",new Student("jack",16));
        Hm.put("smith",new Student("smith",17));
        Hm.put("tom",new Student("tom",18));
        Set<Map.Entry<String, Student>> entries = Hm.entrySet();
        Iterator<Map.Entry<String, Student>> iterator1 = entries.iterator();
        while (iterator1.hasNext()) {
            Map.Entry<String, Student> next = iterator1.next();
            System.out.println(next.getKey()+"--"+next.getValue());
        }

    }

}
class Student{
    String name;
    int age ;
    public Student(String name, int age) {

    }
    public Student(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

}